package org.hbs.blog.code.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.hbs.blog.code.biz.IUserBiz;
import org.hbs.blog.code.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller("userController")
public class UserController implements ControllerData {

	@Resource(name = "userBiz")
	private IUserBiz userBiz;

	@RequestMapping(value = "requestLoginPage")
	public ModelAndView requestLoginPage() {
		return new ModelAndView(new StringBuffer(_FORWARD).append(_ROOT_FOLDER)
				.append("/login.jsp").toString());
	}

	@RequestMapping(value = "requestLoginBusiness")
	public ModelAndView requestLoginBusiness(HttpServletRequest request,
			User userParam) {
		User user = userBiz.selectUserByParam(userParam);
		if (null != user)
			request.getSession(true).setAttribute("currUser", user);
		return new ModelAndView(new StringBuffer(_FORWARD).append(_ROOT_FOLDER)
				.append("/index.jsp").toString());
	}
}
